﻿using MultiLang;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;

namespace Rsdn.Scintilla
{
	/// <summary>
	/// Стиль текста
	/// </summary>
	[TypeConverter(typeof (TextStyleTypeConverter))]
	[DesignTimeVisible(true)]
	public class TextStyle : Component
	{
		#region Private data
		private string _name = "Default";
		private int _number;
		private Font _font = (Font)new FontConverter().ConvertFromString(
			null, CultureInfo.InvariantCulture, "Arial, 10pt");
		private Color _foreColor = Color.Black;
		private Color _backColor = Color.White;
		private bool _eolFilled;
		private CaseMode _caseMode = CaseMode.Mixed;
		private bool _visible = true;
		private bool _hotSpot;
		private PredefinedStyle _predefinedStyle = PredefinedStyle.None;
		#endregion

		#region Initialization
		/// <summary>
		/// Инициализирует компонент
		/// </summary>
		public TextStyle()
		{
		}
		#endregion

		#region Private implementation
		private void OnChanged()
		{
			if (Changed != null)
				Changed(this, EventArgs.Empty);
		}
		#endregion

		#region Internal interface
		internal event EventHandler Changed;
		#endregion

		#region Public interface
		/// <summary>
		/// Инициализирует компонент
		/// </summary>
		public TextStyle(string name, int number, Font font, Color foreColor,
			Color backColor, bool eolFilled, CaseMode caseMode, bool visible, 
			bool hotSpot, PredefinedStyle predefinedStyle)
		{
			_name = name;
			_number = number;
			_font = font;
			_foreColor = foreColor;
			_backColor = backColor;
			_eolFilled = eolFilled;
			_caseMode = caseMode;
			_visible = visible;
			_hotSpot = hotSpot;
			_predefinedStyle = predefinedStyle;
		}

		/// <summary>
		/// Имя стиля
		/// </summary>
		[DefaultValue("Default")]
		public string StyleName
		{
			get { return _name; }
			set 
			{
				if (PredefinedStyle == PredefinedStyle.None)
				{
					_name = value; 
					OnChanged();
				}
			}
		}

		/// <summary>
		/// Номер стиля
		/// </summary>
		[DefaultValue(0)]
		public int Number
		{
			get { return _number; }
			set 
			{
				if (PredefinedStyle == PredefinedStyle.None)
				{
					_number = value;
					OnChanged();
				}
			}
		}

		
		/// <summary>
		/// Шрифт
		/// </summary>
		[DefaultValue(typeof (Font), "Arial; 10pt")]
		public Font Font
		{
			get { return _font; }
			set 
			{
				_font = value; 
				OnChanged();
			}
		}
		
		/// <summary>
		/// Цвет текста
		/// </summary>
		[DefaultValue(typeof (Color), "black")]
		public Color ForeColor
		{
			get { return _foreColor; }
			set 
			{
				_foreColor = value; 
				OnChanged();
			}
		}

		/// <summary>
		/// Цвет фона
		/// </summary>
		[DefaultValue(typeof (Color), "white")]
		public Color BackColor
		{
			get { return _backColor; }
			set 
			{
				_backColor = value;
				OnChanged();
			}
		}

		/// <summary>
		/// Фон заполнен цветом до конца строки
		/// </summary>
		[DefaultValue(false)]
		public bool EolFilled
		{
			get { return _eolFilled; }
			set 
			{
				_eolFilled = value;
				OnChanged();
			}
		}

		/// <summary>
		/// Режим преобразования регистра
		/// </summary>
		[DefaultValue(CaseMode.Mixed)]
		public CaseMode CaseMode
		{
			get { return _caseMode; }
			set 
			{
				_caseMode = value;
				OnChanged();
			}
		}

		/// <summary>
		/// Текст видимый
		/// </summary>
		[DefaultValue(true)]
		public bool Visible
		{
			get { return _visible; }
			set 
			{
				_visible = value;
				OnChanged();
			}
		}

		/// <summary>
		/// Чувствительный к нажатию мыши
		/// </summary>
		[DefaultValue(false)]
		public bool HotSpot
		{
			get { return _hotSpot; }
			set 
			{
				_hotSpot = value;
				OnChanged();
			}
		}

		/// <summary>
		/// Предопределенный стиль
		/// </summary>
		[DefaultValue(PredefinedStyle.None)]
		public PredefinedStyle PredefinedStyle
		{
			get { return _predefinedStyle; }
			set 
			{
				if (value != PredefinedStyle.None)
				{
					StyleName = "Predefined" + value;
					Number = (int)value;
				}
				_predefinedStyle = value;
			}
		}

		/// <summary>
		/// Преобразовать к строке
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return StyleName;
		}

		#endregion
	}
}